# Maintainer: Alexey Pavlov <alexpux@gmail.com>
# Contributor: Renato Silva <br.renatosilva@gmail.com>
# Contributor: Zach Bacon <11doctorwhocanada@gmail.com>
# Contributor: Ray Donnelly <mingw.android@gmail.com>

_realname=wxWidgets
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgbase=mingw-w64-${_realname}
pkgver=3.0.2
pkgrel=15
pkgdesc="A C++ library that lets developers create applications for Windows, Linux and UNIX (mingw-w64)"
arch=('any')
license=("custom:wxWindows")
url="https://www.wxwidgets.org/"
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs"
         "${MINGW_PACKAGE_PREFIX}-cppunit"
         "${MINGW_PACKAGE_PREFIX}-expat"
         "${MINGW_PACKAGE_PREFIX}-libjpeg-turbo"
         "${MINGW_PACKAGE_PREFIX}-libpng"
         "${MINGW_PACKAGE_PREFIX}-libtiff"
         "${MINGW_PACKAGE_PREFIX}-xz"
         "${MINGW_PACKAGE_PREFIX}-zlib"
        )
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc" "${MINGW_PACKAGE_PREFIX}-python2")
options=('strip' 'staticlibs' 'buildflags')
source=(https://downloads.sourceforge.net/wxwindows/wxWidgets-${pkgver}.tar.bz2
        "wxWidgets-3.0.0-gcc-codelight.patch"
        "wxWidgets-3.0.2-msw-dc-orientation-fix.patch"
        "wxWidgets-3.0.2-relax-abi-compatibility-gcc.patch"
        "wxWidgets-3.0.2-relocate-prefix-in-bin-wx-config.patch"
        "wxWidgets-3.0.2-windows-version.patch"
        "wxWidgets-3.0.2-gcc6-abs.patch")
sha256sums=('346879dc554f3ab8d6da2704f651ecb504a22e9d31c17ef5449b129ed711585d'
            'd30e32efbb334ff473e8d8c37152281b19b78a36bd5c766ed9781c7581ee92c2'
            '12f9f474aceb39e5e978e5abbd4288a0ab62d1bcd2ea4a1899c0641fbee8abe1'
            '3138f7b84bf988892f62167afc6fa640ac154b629b243d86413f7c811e508713'
            '7c3b8f6ba275a448a5e82d64c4914acd5aefb8bbb952389688f3e7167a787c56'
            'c73911b55371554f071b0c547630b6fa5b03eec8307e6fb0ae7587833ea96c0e'
            '35baeefa14a4b3b60c580337c96887ea439bbfe052dae236bfce109cf43d1031')

prepare() {
  cd "${srcdir}"/${_realname}-${pkgver}
  patch -p1 -i "${srcdir}"/wxWidgets-3.0.0-gcc-codelight.patch
  patch -p1 -i "${srcdir}"/wxWidgets-3.0.2-msw-dc-orientation-fix.patch
  patch -p1 -i "${srcdir}"/wxWidgets-3.0.2-relax-abi-compatibility-gcc.patch
  patch -p1 -i "${srcdir}"/wxWidgets-3.0.2-relocate-prefix-in-bin-wx-config.patch
  patch -p1 -i "${srcdir}"/wxWidgets-3.0.2-windows-version.patch
  patch -p1 -i "${srcdir}"/wxWidgets-3.0.2-gcc6-abs.patch
}

build() {
  #CXXFLAGS+=" -std=gnu++11"
  [[ -d "${srcdir}"/build-${CARCH} ]] && rm -rf "${srcdir}"/build-${CARCH}
  mkdir -p "${srcdir}"/build-${CARCH} && cd "${srcdir}"/build-${CARCH}

  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --build=${MINGW_CHOST} \
    --enable-shared \
    --enable-iniconf \
    --enable-iff \
    --enable-permissive \
    --enable-unicode \
    --enable-graphics_ctx \
    --enable-accessibility \
    --disable-mediactrl \
    --disable-monolithic \
    --disable-mslu \
    --disable-precomp-headers \
    --with-msw \
    --with-opengl

  make #VERBOSE=1

  #CXXFLAGS+=" -std=gnu++11"
  [[ -d "${srcdir}"/build-${CARCH}-static ]] && rm -rf "${srcdir}"/build-${CARCH}-static
  mkdir -p "${srcdir}"/build-${CARCH}-static && cd "${srcdir}"/build-${CARCH}-static

  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --build=${MINGW_CHOST} \
    --enable-static \
    --disable-shared \
    --enable-iniconf \
    --enable-iff \
    --enable-permissive \
    --enable-unicode \
    --enable-graphics_ctx \
    --enable-accessibility \
    --disable-mediactrl \
    --disable-monolithic \
    --disable-mslu \
    --disable-precomp-headers \
    --with-msw \
    --with-opengl

  make #VERBOSE=1
}

package() {
  cd "${srcdir}"/build-${CARCH}-static
  make DESTDIR="${pkgdir}" install
  mv ${pkgdir}${MINGW_PREFIX}/bin/wx-config{,-static}

  cd "${srcdir}"/build-${CARCH}
  make DESTDIR="${pkgdir}" install

  mv ${pkgdir}${MINGW_PREFIX}/lib/*.dll ${pkgdir}${MINGW_PREFIX}/bin

  # License files
  cd "${srcdir}"/${_realname}-${pkgver}/docs
  install -Dm644 preamble.txt "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/preamble.txt"
  install -Dm644 licence.txt  "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/licence.txt"
  install -Dm644 licendoc.txt "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/licendoc.txt"
  install -Dm644 lgpl.txt     "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/lgpl.txt"
  install -Dm644 gpl.txt      "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/gpl.txt"
  install -Dm644 xserver.txt  "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/xserver.txt"
}
